//
//  CustomTabBarView.m
//  PCSchool
//
//  Created by Arindam Ghosh on 7/12/13.
//  Copyright (c) 2013 Jayanta. All rights reserved.
//

#import "CustomTabBarView.h"

#define ButtonTag 1003


@interface CustomTabBarView ()

@property (nonatomic, assign) UIButton *selectedButton;

@end

@implementation CustomTabBarView
@synthesize tabBarController, selectedButton;


- (void)awakeFromNib
{
    self.selectedButton = (UIButton *)[self viewWithTag:ButtonTag];
    self.selectedButton.selected = YES;
}


+ (CustomTabBarView *)setupTabBarViewOnTabBarController:(UITabBarController *)tabBarController
{
    //UINib *nib = [UINib nibWithNibName:NSStringFromClass(CustomTabBarView.class) bundle:nil];
    UINib *nib4iPad = [UINib nibWithNibName:[NSString stringWithFormat:@"%@_iPad",NSStringFromClass(CustomTabBarView.class)] bundle:nil];
    
    CustomTabBarView *tabBarView = (CustomTabBarView *)[[nib4iPad instantiateWithOwner:self options:nil] objectAtIndex:0];
    tabBarView.tabBarController = tabBarController;
    
    CGRect r = tabBarView.frame;
    r.origin.y = 718.0;
    tabBarView.frame = r;
    // tabBarView.transform = CGAffineTransformMakeRotation(M_PI/6);
    
    tabBarController.tabBar.alpha = 0;
    [tabBarController.view insertSubview:tabBarView aboveSubview:tabBarController.tabBar];
    
    UIView *transitionView = [tabBarController.view.subviews objectAtIndex:0];
    r = transitionView.frame;
    r.size.height = [UIScreen mainScreen].bounds.size.height;
    transitionView.frame = r;
    

    
    return tabBarView;
}


#pragma mark - Button Actions

- (IBAction)tabBarButtonAction:(UIButton *)sender
{
    self.selectedButton.selected = NO;
    self.selectedButton = sender;
    self.selectedButton.selected = YES;
    NSUInteger newIndex = self.selectedButton.tag - ButtonTag;
    [self.tabBarController setSelectedIndex:newIndex];
}


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
